package yz.mr.ReduceJoin;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

public class ReduceJoinMapper extends Mapper<LongWritable,Text,Text,Text> {
    /**
     * @param key   偏移量
     * @param value  一行数据
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
//    @Override
//    protected void map(Text key, Text value, Mapper<Text, IntWritable, Text, Text>.Context context) throws IOException, InterruptedException {
//        String line = value.toString();
//        if (line.contains(",")){
//            //1500100001,施笑槐,22,女,文科六班
//            String[] split = line.split(",");
//            String id = split[0];
//            String otherInfo =split[1]+","+split[2]+","+split[3]+","+split[4];
//            context.write(new Text(id),new Text(otherInfo));
//        }
//        else {
//            //1500100001	406
//            String[] split = line.split("\t");
//            String id = split[0];
//            String score = split[1];
//            context.write(new Text(id),new Text(score));
//
//        }
//    }

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        if (line.contains(",")){
            //1500100001,施笑槐,22,女,文科六班
            String[] split = line.split(",");
            String id = split[0];
            String otherInfo =split[1]+","+split[2]+","+split[3]+","+split[4];
            context.write(new Text(id),new Text(otherInfo));
        }
        else {
            //1500100001	406
            String[] split = line.split("\t");
            String id = split[0];
            String score = split[1];
            context.write(new Text(id),new Text(score));

        }
    }
}
